<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>
<aos:html>
<aos:head title="功能管理">
	<aos:include lib="ext" />
	<aos:base href="autobuilder/builder" />
</aos:head>
<aos:body>
</aos:body>
<aos:onready> 
	<aos:viewport layout="fit">
		<aos:gridpanel id="_datagridpanel" url="list.jhtml" onrender="_datagridpanel_query" onitemdblclick="_w_update_show"  forceFit="false">
			<aos:docked>
				<aos:dockeditem text="新增" tooltip="新增"  onclick="_w_add_show" icon="add.png" />
			    <aos:dockeditem text="修改" tooltip="修改"  onclick="_w_update_show" icon="edit.png"/>
				<aos:dockeditem text="删除" tooltip="删除" onclick="_delete" icon="del.png" />
				<aos:dockeditem text="导入表数据结构" tooltip="导入表数据结构" onclick="_importtabelinfo" icon="icon86.png" />
				<aos:dockeditem text="修改表数据结构" tooltip="修改表数据结构"  onclick="_wtableinfo_update_show" icon="edit.png"/>
				
				<aos:dockeditem text="导出" tooltip="导出" onclick="_exportexcel" icon="icon70.png" />
				<aos:triggerfield emptyText="表名" id="table_name_"  onenterkey="_datagridpanel_query" trigger1Cls="x-form-search-trigger"
					onTrigger1Click="_datagridpanel_query" width="200"/>
				<aos:triggerfield emptyText="字段名" id="column_name_"  onenterkey="_datagridpanel_query" trigger1Cls="x-form-search-trigger"
					onTrigger1Click="_datagridpanel_query" width="200"/>
			</aos:docked>
			<aos:column type="rowno"/>
			<aos:selmodel type="checkbox" mode="multi" />
			<aos:column header="流水号" dataIndex="id_" hidden="true" />
			<aos:column header="表名" dataIndex="table_name_"   width="120"/>
			<aos:column header="字段名" dataIndex="column_name_"  width="120" />
			<aos:column header="数据类型" dataIndex="data_type_"  width="120" />
			<aos:column header="是否为空" dataIndex="is_nullable_"  width="80"  rendererField="bool_"/>
		    <aos:column header="新增检查存在" dataIndex="fieldcheckexist_"  width="80"  rendererField="bool_"/>
			<aos:column header="KEY" dataIndex="column_key_"  width="80" />
			<aos:column header="顺序" dataIndex="ordinal_position_"   width="80"/>
			<aos:column header="字段说明" dataIndex="column_comment_"   width="120" />
			<aos:column header="字段最大长度" dataIndex="character_maximum_length_"  width="120"/>
			<aos:column header="字段最小长度" dataIndex="character_minimum_length_"  width="120"/>
			<aos:column header="显示宽度" dataIndex="display_width_" width="120"/>
			<aos:column header="web端显示" dataIndex="display_web_" width="120" rendererField="bool_"/>
			<aos:column header="否用like" dataIndex="searchlike_" width="120"  rendererField="bool_"/>
			<aos:column header="排序字段" dataIndex="orderby_" width="120" />
			<aos:column header="前台默认值" dataIndex="defaultvalue_" width="120" />
			<aos:column header="系统默认值" dataIndex="osdefault_" width="120" />
		    <aos:column header="web搜索值" dataIndex="web_search_" width="120"  rendererField="bool_"/>
		    <aos:column header="显示gridpanel_column" dataIndex="enable_list_" width="120"  rendererField="bool_"/>
		    <aos:column header="webreadonly" dataIndex="web_readonly_" width="120"  rendererField="bool_"/>
		    <aos:column header="字典" dataIndex="dicfield_" width="120"/>
		    <aos:column header="创建web字段" dataIndex="builder_enable_" rendererField="bool_" width="120"/>
		    <aos:column header="Format" dataIndex="format_" width="120"/>
		    <aos:column header="numeric_precision" dataIndex="numeric_precision_" width="60"/>
		    <aos:column header="numeric_scale" dataIndex="numeric_scale_" width="60"/>
		    <aos:column header="最大值" dataIndex="max_" width="60"/>
		    <aos:column header="最小值" dataIndex="min_" width="60"/>
		</aos:gridpanel>
	</aos:viewport>
	
	<aos:window id="_w_add_data" title="新增">
		<aos:formpanel id="_f_add" width="600"  height="400"   layout="anchor" labelWidth="160" autoScroll="true">
			<aos:textfield name="table_name_" fieldLabel="表名" allowBlank="false" maxLength="50" />
			<aos:textfield name="column_name_" fieldLabel="字段名" allowBlank="false" maxLength="50" />
			<aos:textfield name="data_type_" fieldLabel="数据类型" maxLength="50" />
			<aos:combobox name="is_nullable_" fieldLabel="是否为空"  dicField="bool_" value="1"/>
			<aos:combobox name="column_key_" fieldLabel="KEY" allowBlank="false" value="0" dicField="bool_" />
			<aos:combobox name="fieldcheckexist_" fieldLabel="新增检查存在"  dicField="bool_" value="0"/>
			<aos:numberfield name="ordinal_position_" fieldLabel="顺序"  value="1" />
			<aos:textfield name="column_comment_" fieldLabel="字段说明" maxLength="100" />
			<aos:numberfield name="character_maximum_length_" fieldLabel="字段最大长度" value="1" minWidth="0" maxValue="99999999" />
			<aos:numberfield name="character_minimum_length_" fieldLabel="字段最小长度" value="1" minWidth="0" maxValue="99999999" />
			<aos:numberfield name="display_width_" fieldLabel="显示宽度"   />
			<aos:combobox name="display_web_" fieldLabel="WEB端显示"  dicField="bool_" value="1"/>
			<aos:combobox name="builder_enable_" fieldLabel="创建WEB字段"  dicField="bool_" value="1"/>
			<aos:combobox name="searchlike_" fieldLabel="否用LIKE"  dicField="bool_" value="1"/>
			<aos:combobox name="orderby_" fieldLabel="排序字段"   dicField="orderby_" editable = "true" forceSelection="false"/>
            <aos:textfield name="defaultvalue_" fieldLabel="前台默认值" maxLength="100" />
            <aos:textfield name="osdefault_" fieldLabel="系统默认值" maxLength="100"/>
            <aos:combobox name="web_search_" fieldLabel="界面搜索值"  dicField="bool_" value="1"/>
			<aos:combobox name="enable_list_" fieldLabel="显示gridpanel_column"  dicField="bool_" value="1"/>
			<aos:combobox name="web_readonly_" fieldLabel="否可读列表"  dicField="bool_" value="1"/>
			<aos:textfield name="dicfield_" fieldLabel="字典" maxLength="100"/>
			<aos:textfield name="format_" fieldLabel="Format" maxLength="100"/>
			<aos:numberfield name="numeric_precision_" fieldLabel="numeric_长度"/>
			<aos:numberfield name="numeric_scale_" fieldLabel="numeric_小数位"/>
			<aos:numberfield name="max_" fieldLabel="最大值"/>
			<aos:numberfield name="min_" fieldLabel="最小值"/>
		</aos:formpanel>
		<aos:docked dock="bottom" ui="footer">
			<aos:dockeditem xtype="tbfill" />
			<aos:dockeditem onclick="_f_add_save" text="保存" icon="ok.png" />
			<aos:dockeditem onclick="#_w_add_data.hide();" text="关闭" icon="close.png" />
		</aos:docked>
	</aos:window>
	
	<aos:window id="_w_update_data" title="修改">
		<aos:formpanel id="_f_update" width="600"  height="400" layout="anchor" labelWidth="160" autoScroll="true">
			<aos:hiddenfield name="id_" />
			<aos:textfield name="table_name_" fieldLabel="表名"  readOnly="true" allowBlank="false" maxLength="50" />
			<aos:textfield name="column_name_" fieldLabel="字段名" readOnly="true" allowBlank="false" maxLength="50" />
			<aos:textfield name="data_type_" fieldLabel="数据类型" maxLength="50" />
			<aos:combobox name="is_nullable_" fieldLabel="是否为空"  dicField="bool_" value="1"/>
			<aos:combobox name="column_key_" fieldLabel="KEY" allowBlank="false" value="0" dicField="bool_" />
			<aos:combobox name="fieldcheckexist_" fieldLabel="新增检查存在"  dicField="bool_" value="1"/>
			<aos:numberfield name="ordinal_position_" fieldLabel="顺序"  value="1" />
			<aos:textfield name="column_comment_" fieldLabel="字段说明" maxLength="100"/>
			<aos:numberfield name="character_maximum_length_" fieldLabel="字段最大长度" value="1" minWidth="0"  maxValue="99999999" />
			<aos:numberfield name="character_minimum_length_" fieldLabel="字段最小长度" value="1" minWidth="0" maxValue="99999999" />
			<aos:numberfield name="display_width_" fieldLabel="前台显示宽度"   />
			<aos:combobox name="display_web_" fieldLabel="WEB端显示"  dicField="bool_" value="1"/>
			<aos:combobox name="builder_enable_" fieldLabel="创建WEB字段"  dicField="bool_"/>
			<aos:combobox name="searchlike_" fieldLabel="否用LIKE"  dicField="bool_" value="1"/>
			<aos:combobox name="orderby_" fieldLabel="排序字段"   dicField="orderby_" editable = "true" forceSelection="false"/>
            <aos:textfield name="defaultvalue_" fieldLabel="前台默认值" maxLength="100" />
            <aos:textfield name="osdefault_" fieldLabel="系统默认值" maxLength="100"/>
            <aos:combobox name="web_search_" fieldLabel="界面搜索值"  dicField="bool_" value="1"/>
			<aos:combobox name="enable_list_" fieldLabel="显示gridpanel_column"  dicField="bool_" value="1"/>
			<aos:combobox name="web_readonly_" fieldLabel="否可读列表"  dicField="bool_" value="1"/>
			<aos:textfield name="dicfield_" fieldLabel="字典" maxLength="100" />
			<aos:textfield name="format_" fieldLabel="Format" maxLength="100"/>
			<aos:numberfield name="numeric_precision_" fieldLabel="numeric_长度"/>
			<aos:numberfield name="numeric_scale_" fieldLabel="numeric_小数位"/>
			<aos:numberfield name="max_" fieldLabel="最大值"/>
			<aos:numberfield name="min_" fieldLabel="最小值"/>
		</aos:formpanel>
		<aos:docked dock="bottom" ui="footer">
			<aos:dockeditem xtype="tbfill" />
			<aos:dockeditem onclick="_f_update_save" text="保存" icon="ok.png" />
			<aos:dockeditem onclick="#_w_update_data.hide();" text="关闭" icon="close.png" />
		</aos:docked>
	</aos:window>
	
	<aos:window id="_w_loadtableinfo" title="导入表数据结构">
	          <aos:formpanel id="_f_tableinfo" width="600" layout="anchor" labelWidth="100">
		           <aos:textfield name="table_name_" fieldLabel="表名"   allowBlank="false" maxLength="50" />
		           <aos:textfield name="db_name_" fieldLabel="数据库名"   allowBlank="false" maxLength="50" />
		           <aos:textfield name="table_des_" fieldLabel="描述"   allowBlank="false" maxLength="50" />
		           <aos:combobox name="option_c" fieldLabel="增加"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_u_" fieldLabel="更新"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_s_" fieldLabel="查询"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_d_" fieldLabel="删除"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_export_" fieldLabel="导出"  dicField="bool_" value="1"/>
		           <aos:textfield name="sql_" fieldLabel="SQL语句名"   maxLength="1000" />
		           <aos:numberfield name="width_" fieldLabel="窗口宽度"    value="400"/>
		           <aos:numberfield name="height_" fieldLabel="窗口高度"   value="600"/>
	          </aos:formpanel>
	          <aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="_f_tableinfosave" text="导入" icon="ok.png" />
				<aos:dockeditem onclick="#_w_loadtableinfo.hide();" text="关闭" icon="close.png" />
		    </aos:docked>
	</aos:window>
	
	<aos:window id="_w_updatetableinfo" title="修改表数据结构">
	          <aos:formpanel id="_u_tableinfo" width="600" layout="anchor" labelWidth="70">
	              <aos:hiddenfield name="id_" />
		           <aos:textfield name="table_name_" fieldLabel="表名"   allowBlank="false" maxLength="50" />
		           <aos:textfield name="db_name_" fieldLabel="数据库名"   allowBlank="false" maxLength="50" />
		           <aos:textfield name="table_des_" fieldLabel="描述"   allowBlank="false" maxLength="50" />
		           <aos:combobox name="option_c" fieldLabel="增加"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_u_" fieldLabel="更新"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_s_" fieldLabel="查询"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_d_" fieldLabel="删除"  dicField="bool_" value="1"/>
		           <aos:combobox name="option_export_" fieldLabel="导出"  dicField="bool_" value="1"/>
		           <aos:textfield name="sql_" fieldLabel="SQL语句名"   maxLength="1000" />
		            <aos:numberfield name="width_" fieldLabel="窗口宽度"/>
		           <aos:numberfield name="height_" fieldLabel="窗口高度" />
	          </aos:formpanel>
	          <aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="_f_update_tableinfo_save" text="修改" icon="ok.png" />
				<aos:dockeditem onclick="#_w_updatetableinfo.hide();" text="关闭" icon="close.png" />
		    </aos:docked>
	</aos:window>
	
	<script type="text/javascript">
		function _datagridpanel_query() {
			var params = {
				table_name_ : table_name_.getValue(),
				column_name_ : column_name_.getValue()
			};
			_datagridpanel_store.getProxy().extraParams = params;
			_datagridpanel_store.loadPage(1);
		}
		function getCount() {
			var count = _datagridpanel_store.getCount();
			console.log(count);
		}
		//弹出新增窗口
		function _w_add_show(){
			AOS.reset(_f_add);
			_w_add_data.show();
		}
		//新增
		function _f_add_save(){
				AOS.ajax({
				forms : _f_add,
				url : 'save.jhtml',
				ok : function(data) {
					if (data.appcode === -1) {
                        AOS.err(data.appmsg);
                    } else {
                    	_w_add_data.hide();
    					_datagridpanel_store.reload();
    					_datagridpanel_store();
    					AOS.tip(data.appmsg);
                    }
				}
			});
		}	
		
		//弹出修改窗口
		function _w_update_show(){
			AOS.reset(_f_update);
			var record = AOS.selectone(_datagridpanel);
			if(record){
				_w_update_data.show();
				_f_update.loadRecord(record);
			}
		}
	    
	   //修改read
		function _f_update_save(){
			AOS.ajax({
				forms : _f_update,
				url : 'update.jhtml',
				ok : function(data) {
					if (data.appcode === -1) {
                        AOS.err(data.appmsg);
                    } else {
    					AOS.tip(data.appmsg);	
    					_w_update_data.hide();
    					_datagridpanel_store.reload();
                    }
				}
			}); 
		}
	   
        //删除
	 	function _delete(){
	 				var selection = AOS.selection(_datagridpanel, 'id_');
	 				if(AOS.empty(selection)){
	 					AOS.tip('删除前请先选中数据。');
	 					return;
	 				}
	 				var rows = AOS.rows(_datagridpanel);
	 				var msg =  AOS.merge('确认要删除选中的{0}项目吗？', rows);
	 				AOS.confirm(msg, function(btn){
	 					if(btn === 'cancel'){
	 						AOS.tip('删除操作被取消。');
	 						return;
	 					}
	 					AOS.ajax({
	 						url : 'delete.jhtml',
	 						params:{
	 							aos_rows_: selection
	 						},
	 						ok : function(data) {
	 							if(data.appcode === -1){
	 								AOS.err(data.appmsg);
	 								return ;
	 							}
	 							AOS.tip(data.appmsg);
	 							_datagridpanel_store.reload();
	 						}
	 					});
	 				});
	 			}
        function _exportexcel(){
        	AOS.file('exportexcel.jhtml');
        }
        function _importtabelinfo(){
        	_w_loadtableinfo.show();
        } 
 
        //导入表信息
		function _f_tableinfosave(){
			AOS.ajax({
				forms : _f_tableinfo,
				url : 'importtableinfo.jhtml',
				ok : function(data) {
					if (data.appcode === -1) {
                        AOS.err(data.appmsg);
                    } else {
    					AOS.tip(data.appmsg);	
    					_w_loadtableinfo.hide();
    					_datagridpanel_store.reload();
    					_datagridpanel_store();
                    }
				}
			}); 
		}
		//弹出修改表信息
		function _wtableinfo_update_show(){
			AOS.reset(_u_tableinfo);
			var record = AOS.selectone(_datagridpanel);
			if(record){
			 	AOS.ajax({
					url : 'tableinfo.jhtml',
					params:{
						table_name_: record.raw.table_name_,
					},
					ok : function(data) {
						 _u_tableinfo.down('[name=id_]').setValue(data.id_); 
						 _u_tableinfo.down('[name=table_name_]').setValue(data.table_name_); 
						 _u_tableinfo.down('[name=table_des_]').setValue(data.table_des_); 
						 _u_tableinfo.down('[name=db_name_]').setValue(data.db_name_); 
						 _u_tableinfo.down('[name=option_c]').setValue(data.option_c); 
						 _u_tableinfo.down('[name=option_d_]').setValue(data.option_d_); 
						 _u_tableinfo.down('[name=option_s_]').setValue(data.option_s_); 
						 _u_tableinfo.down('[name=option_u_]').setValue(data.option_u_); 
						 _u_tableinfo.down('[name=option_export_]').setValue(data.option_export_); 
						 _u_tableinfo.down('[name=sql_]').setValue(data.sql_); 
						 _u_tableinfo.down('[name=width_]').setValue(data.width_); 
						 _u_tableinfo.down('[name=height_]').setValue(data.height_); 
					}
				}); 
			   _w_updatetableinfo.show();
			}
	 
		}
		
		//修改
		function _f_update_tableinfo_save(){
			AOS.ajax({
				forms : _u_tableinfo,
				url : 'updatetableinfo.jhtml',
				ok : function(data) {
					if (data.appcode === -1) {
                        AOS.err(data.appmsg);
                    } else {
    					AOS.tip(data.appmsg);	
    					_w_updatetableinfo.hide();
                    }
				}
			}); 
		}
		
	</script>
</aos:onready>
</aos:html>